﻿Imports Runa.Common.Helper
Imports System.Collections
Imports System.Collections.Generic

Namespace Collections

    Public Class FixedQueue(Of T)
        Inherits Queue(Of T)

        Private m_capacity As Integer = 0

        Public ReadOnly Property Capacity() As Integer
            Get
                Return Me.m_capacity
            End Get
        End Property

        Public Sub New(ByVal c As Integer)
            MyBase.New(c)
            If c <= 0 Then Throw New ArgumentException("The argument Capacity must be positive.")
            Me.m_capacity = c
        End Sub

        Public Sub New(ByVal collection As IEnumerable(Of T))
            MyBase.New(collection)
            If collection.Count() <= 0 Then Throw New ArgumentException("The argument Capacity must be positive.")
            Me.m_capacity = collection.Count()
        End Sub

        Public Shadows Sub Enqueue(ByVal item As T)
            While MyBase.LongCount() >= Me.Capacity
                MyBase.Dequeue()
            End While
            MyBase.Enqueue(item)
        End Sub

    End Class

End Namespace